package Operation;

import BOOK.BookList;
import BOOK.Book;
import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("增加图书");
       //String author, int price, String type, String name
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入作者");
        String author= scanner.nextLine();
        System.out.println("请输入价格");
        int price= scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入类型");
        String type= scanner.nextLine();
        System.out.println("请输入书名");
        String name= scanner.nextLine();
        Book book=new Book(author,price,type,name);
        int currentSize= bookList.getUsedSize();
        for (int i = 0; i <currentSize ; i++) {
            Book book1=bookList.getBook(i);
            if(book1.getName().equals(name)){
                System.out.println("你已有这本书，不能进行添加");
                return;
            }
        }
        bookList.setBooks(currentSize,book);
        bookList.setUsedSize(currentSize+1);
    }
}
